package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
<<<<<<< HEAD
<<<<<<< HEAD
import com.itheima.mapper.UserMapper;
=======
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.PageResult;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.Menu;
>>>>>>> zhao
=======
import com.itheima.mapper.UserMapper;
>>>>>>> cheng
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

<<<<<<< HEAD
<<<<<<< HEAD
=======
import java.util.List;

>>>>>>> zhao
=======
>>>>>>> cheng
@Service(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }
<<<<<<< HEAD
<<<<<<< HEAD
=======

    @Override
    public PageResult findAllUser(Integer currentPage, Integer pageSize, String queryString) {

        PageHelper.startPage(currentPage,pageSize);
        List<User> userList = userMapper.findAllUser(queryString);

        PageInfo<User> info = new PageInfo<>(userList);
        return new PageResult(info.getTotal(),info.getList());
    }

    @Override
    public void edit(Integer[] roleIds, User user) {
//        先删除中间表数据
        userMapper.deleteUserAndRoleByUserId(user.getId());
//        修改用户表数据
        userMapper.updateUser(user);

//        插入中间表数据
        userMapper.addUserAndRoleByUserId(user.getId(),roleIds);
    }

    @Override
    public void deleteUserByUserId(Integer id) {
        userMapper.deleteUserAndRoleByUserId(id);
        userMapper.deleteUserByUserId(id);
    }

    @Override
    public void addUser(Integer[] roleIds, User user) {
        userMapper.addUser(user);
        userMapper.addUserAndRoleByUserId(user.getId(),roleIds);
    }


>>>>>>> zhao
=======
>>>>>>> cheng
}
